package  com.pcbly.web.business.user;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.user.UserDetailDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.user.UserDetailBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class UserDetailServiceImp extends BaseServiceImp<UserDetailBean> implements UserDetailService {
	 public UserDetailServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private UserDetailDao userDetailDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setUserDetailDao(UserDetailDao userDetailDao) {
		this.userDetailDao = userDetailDao;
	}
	
	@Override
	public UserDetailBean getUserDetailBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return userDetailDao.get(UserDetailBean.class,id);
	}
	
	@Override
	public void removeUserDetailBeanById(String id) throws Exception{
		userDetailDao.removeUserDetailBeanById(id);
	}
	
	@Override
	public void removeUserDetailBeanByIds(String ids) throws Exception{
		userDetailDao.removeUserDetailBeanByIds(ids);
	}
	
	
	@Override
	public UserDetailBean saveUserDetailBean(UserDetailBean user) throws Exception{
		return userDetailDao.saveUserDetailBean(user);
	}
	
	@Override
	public UserDetailBean updateUserDetailBean(UserDetailBean user) throws Exception{
		userDetailDao.saveObject( user);
		return user;
	}
	public Page<UserDetailBean>  findUserDetailBeanByCond(UserDetailBean bean,
			Page<UserDetailBean> page, String orderByName, boolean asc)
			throws Exception{
		return userDetailDao.findUserDetailBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findUserDetailBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findUserDetailBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = userDetailDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findUserDetailBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = userDetailDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveUserDetailBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		userDetailDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasUserDetailBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return userDetailDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
